package com.xln.jiaju.service.impl;

import com.xln.jiaju.bean.Furn;
import com.xln.jiaju.bean.FurnExample;
import com.xln.jiaju.dao.FurnMapper;
import com.xln.jiaju.service.FurnService;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;


@Service
public class FurnServiceImpl implements FurnService {

    // private ApplicationContext ioc;
    @Resource
    private FurnMapper furnMapper;
    @Override
    public void furnSave(Furn furn) {
        furnMapper.insertSelective(furn);
    }

    @Override
    public List<Furn> queryAll() {

        List<Furn> furns = furnMapper.selectByExample(null);
        return furns;
    }

    @Override
    public void updateFurn(Furn furn) {



      furnMapper.updateByPrimaryKeySelective(furn);
    }

    @Override
    public void deleteFurn(int id) {
        furnMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Furn> queryFurnByName(String name) {
        FurnExample furnExample = new FurnExample();
        FurnExample.Criteria criteria = furnExample.createCriteria();
        if (StringUtils.hasText(name)){
            criteria.andNameLike("%"+name+"%");
        }

        return furnMapper.selectByExample(furnExample);
    }
}
